#include "AiCar.h"
#include "Car_run.h"
#include "WS2812.h"
#include "MYusart.h"

extern char Goto_flag;

extern uint8_t Flag_Move;
static uint8_t Car_State = WAIT_SCAN;
unsigned char Room_Buf[9] = {0x01, 0x02, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A};

void State_Process(void)
{
    Uart_Printf("SYS STATE: %d\n\n", Car_State);
    static unsigned char RoomNum = 0xA0;
    switch (Car_State)
    {
    case WAIT_SCAN:
        if (1 /*Get_Num(unsigned char *)*/)
            RoomNum = Room_Buf[0];
        Car_State = WAIT_LOADING;
        break;
    case WAIT_LOADING:
        if (!HAL_GPIO_ReadPin(WEIGHT_GPIO_Port, WEIGHT_Pin))
        {
            Car_Goto(1);
        TODO: //跑去识别出来的房号
            Car_State = GO_DELIVERY;
            Flag_Move = WORKING;
        }
        break;
    case GO_DELIVERY:
        if (Flag_Move == COMPELETE)
        {
            Flag_Move = LEISURE;
            Car_State = WAIT_UNLOAD;
            ws2812_set_RGB(RGB_RED, 0);
        }
        break;
    case WAIT_UNLOAD:
        if (HAL_GPIO_ReadPin(WEIGHT_GPIO_Port, WEIGHT_Pin))
        {
            Car_State = GO_HOME;
            ws2812_set_RGB(RGB_OFF, 0);
        }

        break;
    case GO_HOME:
        if (Flag_Move == LEISURE)
        {
            Car_Back(Goto_flag);
            Flag_Move = WORKING;
        }
        if (Flag_Move == COMPELETE)
        {
            Flag_Move = LEISURE;
            Car_State = WAIT_SCAN;
            ws2812_set_RGB(RGB_GREEN, 0);
        }
        break;

    default:
        break;
    }
}